#####推广栏位
class OffPromotion
  include Mongoid::Document
  include Mongoid::Timestamps
  include Mongoid::Attributes::Dynamic
  include Mongoid::Paperclip
  field :title, type: String
  field :begin_time, type: DateTime
  field :end_time, type: DateTime


  field :subject_count, type: Integer, default: 20


  has_mongoid_attached_file :banner,
                            :default_url => '/missing.png'
  validates_attachment_content_type :banner, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"]


  validates :title, presence: true #名称，种类不能为空


  belongs_to :userinfo
  has_many :off_promotion_subjects

  attr_readonly *fields.keys

  def banner_full_url

    "#{RestConfig::ELEPHANT_HOST}#{self.banner.url}"
  end


  def begin_time_str
    begin_time.strftime("%Y-%m-%d %H:%M:%S")
  end


  def end_time_str
    end_time.strftime("%Y-%m-%d %H:%M:%S")
  end

  def created_at_str
    created_at.strftime("%Y-%m-%d %H:%M:%S")
  end

end
